home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / misc / xref_v1.1.lha / XRef / Tools / lib / timecalc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-13  |  1.7 KB  |  82 lines

  1. /*
  2. ** $PROJECT: xrefsupport.lib
  3. **
  4. ** $VER: timecalc.c 1.3 (24.09.94)
  5. **
  6. ** by
  7. **
  8. ** Stefan Ruppert , Windthorststraße 5 , 65439 Flörsheim , GERMANY
  9. **
  10. ** (C) Copyright 1994
  11. ** All Rights Reserved !
  12. **
  13. ** $HISTORY:
  14. **
  15. ** 24.09.94 : 001.003 :  if totalsize == actualsize), set secs
  16. ** 17.09.94 : 001.002 :  tc_Update now check for <= 0 , this fixes a devision by zero bug
  17. ** 11.09.94 : 001.001 :  initial
  18. */
  19.  
  20. /* ------------------------------- includes ------------------------------- */
  21.  
  22. #include "/source/def.h"
  23.  
  24. #include "xrefsupport.h"
  25.  
  26. /* ------------------------------ functions ------------------------------- */
  27.  
  28. void time_calc(struct TimeCalc *time,ULONG actual,ULONG total)
  29. {
  30.    ULONG sec;
  31.    ULONG mic;
  32.  
  33.    CurrentTime(&sec,&mic);
  34.  
  35.    sec -= time->tc_BeginSec;
  36.  
  37.    if(sec > 0)
  38.       mic = (1000000 - time->tc_BeginMic) + mic;
  39.  
  40.    sec += (mic / 1000000);
  41.  
  42.    if(sec > time->tc_LastSec)
  43.    {
  44.       time->tc_LastSec = sec;
  45.  
  46.       if(time->tc_TimeCalled > 3)
  47.          time->tc_Update += 5;
  48.       else if(time->tc_TimeCalled < 3)
  49.       {
  50.          time->tc_Update -= 5;
  51.          if(time->tc_Update <= 0)
  52.             time->tc_Update = 1;
  53.       }
  54.  
  55.       if(total > 1024 * 1024 / 2 && actual > 1024)
  56.       {
  57.          total  >>=  10;
  58.          actual >>=  10;
  59.       }
  60.  
  61.       time->tc_TimeCalled = 0;
  62.  
  63.       time->tc_Secs[0] = sec;
  64.       time->tc_Secs[1] = (sec * total) / actual;
  65.       time->tc_Secs[2] = time->tc_Secs[1] - time->tc_Secs[0];
  66.  
  67.    } else if(actual == total)
  68.    {
  69.       time->tc_Secs[0] = sec;
  70.       time->tc_Secs[1] = sec;
  71.       time->tc_Secs[2] = 0;
  72.    } else
  73.       time->tc_TimeCalled++;
  74. }
  75.  
  76. void time_init(struct TimeCalc *time,ULONG update)
  77. {
  78.    CurrentTime(&time->tc_BeginSec,&time->tc_BeginMic);
  79.    time->tc_Update = update;
  80. }
  81.  
  82.